# Contributor: @ifurther <55025025+ifurther@users.noreply.github.com>

_realname=hugo
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.109.0
pkgrel=1
pkgdesc='A Fast and Flexible Static Site Generator built with love by bep, spf13 and friends in Go. (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://github.com/gohugoio/hugo"
license=('spdx:Apache-2.0')
makedepends=("${MINGW_PACKAGE_PREFIX}-go" "${MINGW_PACKAGE_PREFIX}-cc" "git")
optdepends=("git: To interact with repositories")
options=('!strip')
source=("$_realname-$pkgver.tar.gz::$url/archive/refs/tags/v$pkgver.tar.gz")
sha256sums=('35a5ba92057fe2c20b2218c374e762887021e978511d19bbe81ce4d9c21f0c78')

build() {
    cd "${_realname}-$pkgver"
    export GOOS=windows
    export GOROOT=${MINGW_PREFIX}/lib/go
    export CGO_CPPFLAGS="${CPPFLAGS}"
    export CGO_CFLAGS="${CFLAGS}"
    export CGO_CXXFLAGS="${CXXFLAGS}"
    export CGO_LDFLAGS="${LDFLAGS}"
    export GO_LDFLAGS="-s -w"
    export GOFLAGS="-trimpath -mod=readonly -modcacherw -ldflags=-linkmode=external"

    go build
}

check(){
    cd "${_realname}-$pkgver"
    go test
}

package() {
    cd "${_realname}-$pkgver"
    install -Dm755 "hugo.exe" "${pkgdir}${MINGW_PREFIX}/bin/hugo.exe"
    install -Dm644 "LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
    install -Dm644 "README.md" "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/README.md"
}
